package com.way.getWeather;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;

import org.json.JSONException;
import org.json.JSONObject;

public class MyWeather {
	public static String city;
	public static String temp1;
	public static String weather1;
	public static String img1;

	public static void getWeather() {
				try {
					URL url = new URL(
							"http://m.weather.com.cn/data/101250101.html");
					InputStream is = url.openStream();
					ByteArrayOutputStream bos = new ByteArrayOutputStream();
					int len = -1;
					byte[] buffer = new byte[1024];
					while ((len = is.read(buffer)) != -1) {
						bos.write(buffer, 0, len);
					}
					String info = bos.toString("utf-8");
					JSONObject dataJson = new JSONObject(info);
					JSONObject json = dataJson.getJSONObject("weatherinfo");
					city = json.getString("city");
					temp1 = json.getString("temp1");
					weather1 = json.getString("weather1");
					img1 = json.getString("img1");
					bos.close();
					is.close();
				} catch (MalformedURLException e) {
					e.printStackTrace();
				} catch (IOException e) {
					e.printStackTrace();
				} catch (JSONException e) {
					e.printStackTrace();
				}
	}

}
